const mongoose = require('mongoose')
const db = require('./db')
const Schema = mongoose.Schema

//创建文章articleSchema

const forumSchema = new mongoose.Schema({
    classify: { type: String, required: true }, //文章的分类
    title: { type: String, required: true }, //文章的标题
    publishDate: { type: Date, required: true, default: Date.now }, //文章的发布时间
    content: { type: String, required: true }, //文章的内容
    readyNum: { type: Number, required: true, default: 0 }, //文章的访问量
    isAdmin: { type: Boolean, required: true }, //是不是管理员
    userInfo: { type: Schema.Types.ObjectId, ref: 'user_lists' }, //文章作者的相关信息
    ratings: [{ type: Schema.Types.ObjectId, ref: 'rating_lists' }], //文章的分类
    ratingUser: [{ type: Schema.Types.ObjectId, ref: 'user_lists' }], //文章的分类

})

const ratingsSchema = new mongoose.Schema({
    rating_txt: { type: String, required: true }, //文章的分类
    author: { type: String, required: true },
    date: { type: Date, required: true, default: Date.now },
    avatar: { type: String, required: true },
    like_num: { type: Number, required: true, default: 0 },
    like_lists: { type: Object, default: {} },
})

const articleModel = db.model('article_lists', forumSchema)
const ratingsModel = db.model('rating_lists', ratingsSchema)

module.exports = { articleModel, ratingsModel }